package com.ellecity06.cwhiskymall.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.request.AddressAddRequest
import com.ellecity06.cwhiskymall.databinding.ItemAddressBinding

/**
 * @author ellecity06
 * @time 2024/10/31 15:42
 * @des
 */
class AddressAdapter : BaseAdapter<AddressAddRequest, ItemAddressBinding>() {

    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemAddressBinding {
        return ItemAddressBinding.inflate(layoutInflater,parent,false)
    }

    override fun convert(binding: ItemAddressBinding, position: Int, item: AddressAddRequest) {
        binding.tvName.text = item.memberName
        binding.tvPhone.text = item.telMobile
        binding.tvAddress.text = "${item.addressAll}${item.detailAddress}"
        checkState(binding.ivCheck, item.isDefault == 1)

    }

    private fun checkState(imageview: ImageView, checked: Boolean) {
        imageview.setImageResource(if (checked) R.mipmap.icon_address_check_checked else R.mipmap.icon_address_check_default)

    }
}